<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
    </head>
    <body>
        <div id="app">
            <ul>
                <li><router-link to="/home">Home</router-link></li>
                <li><router-link :to="{name:'user',params:{userId:'100'}}">用户100</router-link></li>
            </ul>
            <router-view></router-view>
        </div>
        <script src="vue.js"></script>
        <script src="vue-router.js"></script>
        <script>
const User  = {
    template:`
    <div>
       <p>User {{$route.params.userId}}</p>
    </div>
    `
}
const Home = {
    template:`<div>Home</div>`
}
const Register = {
    template:`<div>Register:{{$route.query}}</div>`
}
const routes = [
    {name:"home",path:'/home',component:Home},
    {
        name:'user',
        path:'/user/:userId',
        component:User
    },
    {
        name:'register',
        path:'/register',
        component:Register
    }
]
//创建路由实例
var router = new VueRouter({
    //mode:'history',
    routes
});
var vm = new Vue({
    el:'#app',
    router
});
setTimeout(()=>{
    router.push('/user/100',()=>{
    console.log('callback 跳转成功1')
},()=>{
    console.error('callback 跳转失败1')
})
},3000);

/* .then(
    ()=>{
    console.log('then 跳转成功2')
},()=>{
    console.error('then 跳转失败2')
}, */

</script>
    </body>
</html>